﻿using System;
using System.Collections.Generic;
using System.Data.Common;
using WpfApp1.Acme.DataSourcePackage;
using WpfApp1.Acme.Template;
using WpfApp1.Exmple.UserService;

namespace WpfApp1.Exmple.UserDao {
    //[Component]
    internal class UserMapper : RowMapper<List<User>>{
        List<User> list = new List<User>();
        public List<User> mapRow(DbDataReader reader) {
            User user = new User();
            user.Id = Convert.ToInt32(reader["id"]);
            user.Name = (string)reader["name"];
            user.Password = (string)reader["password"];
            list.Add(user);
            return list;
        }
        
        public void testDB() {
            //string sql = "select * from testTable where id > @id";
            //string sql = @"BEGIN;
            //            INSERT into testTable(id, name, password) values(4, 'tangjiachang123', '123213');
            //            update testTable set password = 'admin123' where id = 4;
            //            COMMIT;";
            //List<User> listUser = dataSourceOperation.ExecuteReader<List<User>>(sql, ApplicationContext.getBean("userMapper"), 2);
            //foreach (User user in listUser) {
            //    Debug.WriteLine("UserMapper testDB method: id:" + user.Name);
            //}
            //object obj = dataSourceOperation.Executescalar(sql, 2);
            //Debug.WriteLine("UserMapper testDB method : " + obj);
            //dataSourceOperation.close();
        }
    }
}
